package com.formerlyknownasprince.wheresmystuff.models;

import java.io.IOException;

import org.apache.http.client.ClientProtocolException;
import org.codehaus.jackson.JsonNode;
import org.codehaus.jackson.JsonParseException;
import org.codehaus.jackson.annotate.JsonProperty;
import org.codehaus.jackson.map.JsonMappingException;
import org.codehaus.jackson.map.ObjectMapper;


public class Tag extends ServerObject {
	@JsonProperty("title")
	private String title;
	
	protected static String baseURL = "/tags/";

	public Tag() {
		this.setTitle("");
	}
	public Tag(String title) throws ClientProtocolException, IOException {
		om = new ObjectMapper();
		if (title.indexOf('{') != -1) {
			//json passed in, not a title
			Tag t = om.readValue(title, Tag.class);
			this.setTitle(t.getTitle());
		} else {
			this.setTitle(title);
			try {
				this.create();
			} catch (SyncException se) {
				se.printStackTrace();
			}
		}
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}
	
	public int getId() {
		return this.id;
	}
	
	public JsonNode toJson() {
		return om.valueToTree(this);
	}
	
	@Override
	public String getBaseURL() {
		return this.baseURL;
	}
}
